/*
 * Author: Vassilis
 */

#include "Tile.h"
#include "Tileset.h"
#include <cstdlib>

Tile::Tile(unsigned int sGid,unsigned long flag /* = 0*/)
{
    m_flipX = sGid & maskX;
    m_flipY = sGid & maskY;
    m_gid = sGid;
    m_tileset = NULL;
    this->m_flag = flag;
}

Tile::~Tile()
{
}

void Tile::SetRect(unsigned x, unsigned y, unsigned width, unsigned height)
{
    m_clip.Set(static_cast<int>(y), static_cast<int>(x), static_cast<int>(height), static_cast<int>(width));
}

void Tile::SetRect(const Math::Rect& rect)
{
    m_clip = rect;
}

void Tile::SetGid(int sGid)
{
    m_gid = sGid;
}

int Tile::GetTilesetID() const
{
    int sGid = m_gid;
    if(m_flipX)
        sGid = sGid ^ maskX;
    if(m_flipY)
        sGid = sGid ^ maskY;
    return sGid;
}

void Tile::SetTileset(Tileset* sTileset)
{
    m_tileset = sTileset;
}

Tileset *Tile::GetTileset()
{
    return m_tileset;
}

int Tile::GetGid() const
{
    return m_gid;
}

const Math::Rect &Tile::GetClip() const
{
    return m_clip;
}

bool Tile::IsFlipY() const
{
    return m_flipY;
}

bool Tile::IsFlipX() const
{
    return m_flipX;
}

